using System;
using System.Collections.Generic;

namespace Game500.ClientServerCommon.Src
{
  public class ArgumentBag
  {
    private readonly Dictionary<string, string> myArgs = new Dictionary<string, string>();

    public ArgumentBag(IEnumerable<string> args)
    {
      string currentKey = "";
      foreach (string arg in args)
      {
        if (arg[0] == '-')
        {
          if (currentKey != "") throw new Exception("Invalid command line format");
          currentKey = arg;
          continue;
        }
        myArgs[currentKey] = arg;
        currentKey = "";
      }
    }

    public string GetValue(string key, string defaultValue)
    {
      string result;
      if (myArgs.TryGetValue(key, out result)) return result;
      return defaultValue;
    }
  }
}